import 'package:flutter/material.dart';
import 'package:flutter_09_game/base/widget/base_list_more_get_builder.dart';
import 'package:flutter_09_game/config/app_color.dart';
import 'package:flutter_09_game/generated/assets.dart';
import 'package:flutter_09_game/generated/locales.g.dart';
import 'package:flutter_09_game/pages/deposit/models/model_record_recharge.dart';
import 'package:flutter_09_game/user/app_user_manager.dart';
import 'package:flutter_09_game/utils/extensions/num_ext.dart';
import 'package:flutter_09_game/utils/utils_other.dart';
import 'package:flutter_09_game/utils/utils_time.dart';
import 'package:flutter_09_game/widgets/btn_dropdown.dart';
import 'package:flutter_09_game/widgets/dialog/common_normal_sheet.dart';
import 'package:flutter_09_game/pages/deposit/widgets/widget_recharge_detail.dart';
import 'package:flutter_09_game/widgets/empty/empty_no_data.dart';
import 'package:flutter_09_game/widgets/image/auto_image.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

import 'deposit_record_recharge_logic.dart';

class DepositRecordRechargePage extends StatelessWidget {
  DepositRecordRechargePage({super.key});

  final DepositRecordRechargeLogic logic =
      Get.put(DepositRecordRechargeLogic());

  @override
  Widget build(BuildContext context) {
    return BaseListMoreGetBuilder<DepositRecordRechargeLogic>(
      emptyBuilder: () {
        return SizedBox(
          width: 1.sw,
          child: Padding(
            padding: EdgeInsets.only(top: 108.w),
            child: EmptyNoData.notDataView(),
          ),
        );
      },
      bodyTopViewBuilder: (l) {
        return Container(
          padding: EdgeInsets.all(16.w).copyWith(bottom: 24.w),
          decoration: BoxDecoration(
            color: AppColor.navBgColor,
            borderRadius: BorderRadius.only(
              bottomLeft: Radius.circular(30.w),
              bottomRight: Radius.circular(30.w),
            ),
          ),
          child: Obx(() {
            return Row(
              children: [
                Expanded(
                    child: _buildTopDropdown([
                  LocaleKeys.allCoins.tr,
                  ...AppUserManager().walletList.map((f) => f.symbol ?? '')
                ],
                        value: logic.symbolRx.value.isEmpty
                            ? LocaleKeys.allCoins.tr
                            : logic.symbolRx.value, onChanged: (value) {
                  if (value == LocaleKeys.allCoins.tr) {
                    logic.symbolRx.value = '';
                  } else {
                    logic.symbolRx.value = value;
                  }
                })),
                8.horizontalSpace,
                Expanded(
                    child: _buildTopDropdown([
                  LocaleKeys.today.tr,
                  LocaleKeys.yesterday.tr,
                  LocaleKeys.threeDays.tr,
                  LocaleKeys.sevenDays.tr,
                  LocaleKeys.custom.tr,
                ], btnColor: AppColor.primary, value: logic.timeRx.value,
                        onChanged: (value) {
                  logic.updateTimeSelection(value);
                })),
              ],
            );
          }),
        );
      },
      builder: (_) {
        return SingleChildScrollView(
            padding: EdgeInsets.only(bottom: 16.w),
            child: Container(
              margin:
                  EdgeInsets.symmetric(horizontal: 16.w).copyWith(top: 16.w),
              padding: EdgeInsets.all(12.w),
              decoration: BoxDecoration(
                color: AppColor.navBgColor,
                borderRadius: BorderRadius.circular(16.w),
              ),
              child: Column(
                children: [
                  Row(
                    children: [
                      _buildHeaderCell(LocaleKeys.time.tr, 94.w),
                      8.horizontalSpace,
                      _buildHeaderCell(LocaleKeys.currency.tr, 60.w),
                      8.horizontalSpace,
                      Expanded(child: _buildHeaderCell('金额', null)),
                      8.horizontalSpace,
                      _buildHeaderCell('状态', 72.5.w),
                    ],
                  ),

                  8.verticalSpaceFromWidth,
                  ...logic.list.map(
                    ( value) {
                      ModelRecordRecharge record = value;
                      return Container(
                        margin: EdgeInsets.only(bottom: 4.w),
                        child: Row(
                          children: [
                            Container(
                              width: 94.w,
                              height: 40.w,
                              // color: Colors.red,
                              alignment: Alignment.centerLeft,
                              child: Text(
                                UtilsTime.depositFormatTime(record.createdAt),
                                style: TextStyle(
                                  color: AppColor.textPrimary.withOpacity(0.7),
                                  fontSize: 12.sp,
                                  fontWeight: FontWeight.w400,
                                ),
                              ),
                            ),
                            8.horizontalSpace,
                            SizedBox(
                              width: 60.w,
                              height: 40.w,
                              child: Row(
                                children: [
                                  AutoImage(
                                    UtilsOther().getAmountTagIcon(record.symbol),
                                    width: 16.w,
                                    height: 16.w,
                                  ),
                                  4.horizontalSpace,
                                  Expanded(
                                    child: Text(
                                      record.symbol ?? '',
                                      style: TextStyle(
                                        color:
                                        AppColor.textPrimary.withOpacity(0.7),
                                        fontSize: 12.sp,
                                        fontWeight: FontWeight.w400,
                                      ),
                                    ),
                                  ),
                                ],
                              ),
                            ),
                            8.horizontalSpace,
                            Expanded(
                                child: Container(
                                  height: 40.w,
                                  alignment: Alignment.centerLeft,
                                  child: Text(
                                      "+${record.amount?.formatLimiting() ?? ''}",//   record.amount?.formatLimiting(),//   ,
                                    style: TextStyle(
                                      color: AppColor.textPrimary,
                                      fontSize: 12.sp,
                                      fontWeight: FontWeight.w600,
                                    ),
                                  ),
                                )),
                            8.horizontalSpace,
                            GestureDetector(
                              onTap: () {
                                CommonNormalSheet(
                                  title: LocaleKeys.rechargeDetails.tr,
                                  child: WidgetRechargeDetail(
                                    record: record,
                                  ),
                                ).show();
                              },
                              child: SizedBox(
                                width: 72.5.w,
                                height: 40.w,
                                child: Row(
                                  children: [
                                    Expanded(
                                      child: Text(
                                        LocaleKeys.rechargeSuccess.tr,
                                        //   _getStatusText(record.status),
                                        style: TextStyle(
                                          color: AppColor.homePrizePoolIndicator,
                                          // color: _getStatusColor(record.status),
                                          fontSize: 12.sp,
                                          fontWeight: FontWeight.w400,
                                        ),
                                      ),
                                    ),
                                    4.horizontalSpace,
                                    AutoImage(
                                      Assets.mineRigthtRight,
                                      width: 20.w,
                                      height: 20.w,
                                      color:
                                      AppColor.textPrimary.withOpacity(0.5),
                                    ),
                                  ],
                                ),
                              ),
                            )
                          ],
                        ),
                      );

                    }

                  )
                  // if (records.isNotEmpty) _buildNoMoreData(),
                ],
              ),
            ));

        // return SingleChildScrollView(
        //   child: Column(
        //     children: [
        //     ,
        //     ],
        //   ),
        // );
      },
    );
    // return Container();
  }

  /// 构建表头单元格
  Widget _buildHeaderCell(String title, double? width) {
    return Container(
      width: width,
      height: 40.w,
      alignment: Alignment.centerLeft,
      child: Text(
        title,
        style: TextStyle(
          color: AppColor.textPrimary.withOpacity(0.94),
          fontSize: 14.sp,
          fontWeight: FontWeight.w600,
        ),
      ),
    );
  }

  Widget _buildTopDropdown(List<String> items,
      {required String value,
      required Function(String) onChanged,
      Color? btnColor}) {
    return BtnDropdown(
        items: items,
        value: value,
        // width: 1.sw - 32.w,
        // mainAxisAlignment: MainAxisAlignment.start,
        onChanged: (value) {
          onChanged.call(value);
        },
        child: Container(
          padding: EdgeInsets.symmetric(horizontal: 10.w, vertical: 12.w),
          decoration: BoxDecoration(
              border: Border(
                  bottom: BorderSide(
                      color: AppColor.textPrimary.withOpacity(0.15), width: 1)),
              color: Colors.black.withOpacity(0.3),
              borderRadius: BorderRadius.circular(8.w)),
          child: Row(
            children: [
              Expanded(
                  child: Text(
                value,
                style: TextStyle(
                  fontSize: 14.sp,
                  fontWeight: FontWeight.w900,
                  color: btnColor ?? AppColor.textPrimary.withOpacity(0.94),
                ),
              )),
              AutoImage(
                Assets.promotionCommissionCaretDown,
                width: 16.w,
              )
            ],
          ),
        ));
  }


}
